<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>axios测试</title>
    <script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>

</head>
<body>
    <div id="app">
        <button @click="sendRequest">请求</button>
    </div>
</body>
<script>
    axios.interceptors.request.use(function (config) {
        config.headers.myhead = 'fdsfsdf';
        return config;
    }, function (error) {
        // 对请求错误做些什么
        return Promise.reject(error);
    });
    new Vue({
        el: '#app',
        methods: {
            sendRequest() {
                axios
                    .get('https://www.runoob.com/try/ajax/json_demo.json')
                    .then(response => (alert(response.data)))
                    .catch(function (error) { // 请求失败处理
                        console.log(error);
                    });

            }
        }
    })
</script>
</html>
